package imobiliaria2

import org.grails.datastore.gorm.finders.FindByFinder;
import org.grails.plugin.filterpane.FilterPaneUtils;

/**
 * ImovelController
 * A controller class handles incoming web requests and performs actions such as redirects, rendering views and so on.
 */
class ImovelController {

	static scaffold = Imovel
	
	def filterPaneService
	def index = { redirect(action:list,params:params)
	}
	
def list = {
		if(!params.max) params.max = 10
		log.debug("Imovel is ${Imovel} or type ${Imovel.class}")
		[ imovelInstanceList: Imovel.list( params ), filterParams: FilterPaneUtils.extractFilterParams(params) ]
	}
	
	def filter = {
		if(!params.max) params.max = 10
		render( view:'list', model:[ imovelInstanceList: filterPaneService.filter( params, Imovel ), bookCount: filterPaneService.count( params, Imovel ), filterParams: FilterPaneUtils.extractFilterParams(params), params:params ] )
	}
	
	def show = {
		def imovel = Imovel.get( params.id )
		
		if(!imovel) {
			flash.message = "Imovel nao encontrado com o id ${params.id}"
			redirect(action:list)
		}
		else { return [ imovelInstance : imovel ]
		}
	}
}
